//
//  ViewController.m
//  QQ聊天页面
//
//  Created by 宋 on 16/3/8.
//  Copyright © 2016年 宋. All rights reserved.
//

#import "ViewController.h"
#import "Xgroup.h"
@interface ViewController ()<UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,strong)NSArray * messages;
@end

@implementation ViewController
-(NSArray *)messages{
    if (_messages == nil) {
        NSString *path = [[NSBundle mainBundle]pathForResource:@"message.plist" ofType:nil];
        //加载
        NSArray *mes = [[NSArray alloc]initWithContentsOfFile:path];
        //封装数据模型
        NSMutableArray *messageArray = [NSMutableArray array];
                                        
        for (NSDictionary *dict in mes) {
            //创建模型对象
            Xgroup *xmessage = [Xgroup messageWithDcit:dict];
            [messageArray addObject:xmessage];
        }
        _messages =messageArray;
    }
    return _messages;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.dataSource = self;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //return 3;
    //Xgroup *messages =self.messages[section];
    return self.messages.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    //cell.textLabel.text = @"漂洋过海来看你❀";
    Xgroup *messages =self.messages[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:messages.heardimage];
    cell.textLabel.text = messages.message;
    //NSLog(@"count =%d",messages.message);
    return cell;
}

@end
